import axios from "axios";
import qs from "qs";
// 设置全局路径

axios.defaults.baseURL = 'http://110.41.43.118:3008';

export default{
	// 通用get方法
    async getData(URL: string,Data:object = {}){
        let even = await axios.get(URL , {params : Data} );
        if(even.data.code !=0){
            console.log('getData方法错误');
			console.log(even);
			return;
        };
        return even.data.data;
        
    },
	// 通用post方法
    async postData(URL: string,Data:object = {}) {
        let even = await axios.post(URL,qs.stringify(Data));
        if(even.data.code !=0){
            console.log('postData方法错误');
			console.log(even);
			return;
        };
        return even.data.data;
    },

    //检查用户名 登录 注册
    async getUserData(url:string,data = {}){
        let even = await axios.post(url,qs.stringify(data));
        return even.data;
    },
	// 请求购物车数据方法
    async getCarData(url:string,data = {}){
        let even = await axios.post(url,qs.stringify(data));
        if(even.data.code !== 0){
			console.log('getcartData方法错误');
			console.log(even);
			return;
		};

        //ok数据
		return even.data.data || even.data;
    },

    // 封装 地址 的方法
	async getAddressData(url: string, data = {}){
		let even = await axios.post(url, qs.stringify(data));
	
		if(even.data.code !== 0){
			console.log('getAddressData方法错误');
			console.log(even);
			return;
		};
		//ok数据
		return even.data.data || even.data;
	},

    // 封装 结算 的方法
	async getSettlementData(url: string, data = {}){
		let result = await axios.post(url, qs.stringify(data));
		if(result.data.code !== 0){
			console.log('getSettlementData方法错误');
			console.log(result);
			return;
		};
		//ok数据
		return result.data.data || result.data;
	},
	// 订单请求数据
	async orderData(URL: string,Data:object = {}) {
        let even = await axios.post(URL,qs.stringify(Data));
        
        return even.data.data || even.data;
    },
	// 支付请求
	async payData(URL: string,Data:object = {}) {
        let even = await axios.post(URL,qs.stringify(Data));
        
		return even.data.data || even.data;
    },


}
